package com.lonni.rpc.core.loadbalance;

import com.lonni.rpc.core.model.RpcRequest;
import com.lonni.rpc.core.model.ServiceAddress;
import org.apache.commons.lang3.RandomUtils;

import java.util.List;

/**
 * 随机地址
 * @author: lonni
 * @CreateTime: 2024-06-27  21:02
 * @Description:
 */
public class RandomLoadBalance extends AbstractLoadBalance {
    /**
     * 查询地址
     *
     * @param uris
     * @param request
     * @return
     */
    @Override
    public ServiceAddress doSelectAddress(List<ServiceAddress> uris, RpcRequest request) {
        int i = RandomUtils.nextInt(0, uris.size());
        return uris.get(i);
    }
}
